function createOverload() {
    const fnMap = new Map()

    function overload(...args) {
        const key = args.map(arg => typeof arg).join(',')
        const fn = fnMap.get(key)
        if (!fn) {
            throw new Error('Method not implemented')
        }
        return fn.apply(this, args)
    }

    overload.addImpl = function (...args) {
        const fn = args.pop()
        if (typeof fn !== 'function') {
            throw new Error('Last arg must be an function')
        }
        const key = args.join(',')
        fnMap.set(key, fn)
    }

    return overload
}

const getUser = createOverload()

getUser.addImpl('string', (name, nickname = 'Tom') => {
    console.log(`查询${name}-${nickname}用户`)
})

getUser.addImpl('string', 'string', (name, nickname = 'Tom') => {
    console.log(`查询${name}-${nickname}用户`)
})

getUser('tom', 'jerry')

